<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;


class Prescription extends Model
{

    use SoftDelete;




    // 表名
    protected $name = 'prescription';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [

    ];

    public function user()
    {
        return $this->belongsTo('user', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function getCreateTimeAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }
    public function orderGoods()
    {
        return $this->hasMany('PrescriptionGoods', 'prescription_id', 'id');
    }

}
